public class Demo14 {
    //创建两个锁对象 locker1,locker2
    public static Object locker1=new Object();
    public static Object locker2=new Object();
    //创建两个线程t1,t2,给线程t1加locker1的锁，给t2加locker2的锁，在两线程分别持有锁的情况下尝试获取对方的锁（死锁）
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            synchronized (locker1){
                System.out.println("线程1获取到locker1");
                synchronized (locker2){
                    System.out.println("线程1获取到locker2");
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (locker2){
                System.out.println("线程2获取到locker2");
                synchronized (locker1){
                    System.out.println("线程2获取到locker1");
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
